package com.hoow.shakoow.shake.payBilling

import com.android.billingclient.api.BillingClient
import com.android.billingclient.api.BillingResult
import com.android.billingclient.api.Purchase
import com.android.billingclient.api.PurchasesUpdatedListener

class ShakePurchasesListener : PurchasesUpdatedListener {
    override fun onPurchasesUpdated(result: BillingResult, purchases: MutableList<Purchase>?) {
        if (result.responseCode == BillingClient.BillingResponseCode.OK && purchases != null) {
            for (purchase in purchases) {
                // 处理购买成功的情况
                handlePurchase(purchase)
            }
        } else if (result.responseCode == BillingClient.BillingResponseCode.USER_CANCELED) {
            // 用户取消购买
            handleUserCancelled()
        } else {
            // 处理其他错误情况
            handleError(result.responseCode)
        }
    }

    private fun handlePurchase(purchase: Purchase) {
        // 处理购买成功的逻辑，例如向用户提供购买的功能或服务
        // 可以通过 purchase 对象获取购买的详细信息
    }

    private fun handleUserCancelled() {
        // 用户取消购买时的处理逻辑
    }

    private fun handleError(responseCode: Int) {
        // 处理其他错误情况，可以根据 responseCode 提供相应的用户反馈
    }

}